//Accepted
#include <vector>
#include <set>
#include <algorithm>
#include <string>
#include <cmath>
#include <queue>
#include <map>
#include <iostream>
#include <list>
#include <deque>
#include <cstdio>
#include <cstring>
#include <cstdlib>
using namespace std;

char s[20][20];
int n, m, i, j, k, x, sum=0;
vector< pair<int,int> > v;

int rec(){
	
}
int main (){
	//freopen("in.txt", "r", stdin);//freopen("out.txt", "w", stdout);
	
	scanf("%d%d", &n, &m);
	for(i=0;i<n;++i)scanf("%s", s[i]);
	
	for(i=0;i<n;++i){
		for(j=0;j<m;++j){
			
			if(s[i][j]=='W'){
				
				x=0;
				if(i-1>=0)if(s[i-1][j]=='P')++x;
				
				if(i+1<n)if(s[i+1][j]=='P')++x;
				
				if(j-1>=0)if(s[i][j-1]=='P')++x;
				
				if(j+1<m)if(s[i][j+1]=='P')++x;
				if(x)++sum;
			}
		}
	}
	printf("%d", sum);
	
	
	
	return 0;
}
